package github.kawaiior.yuanchuxiuzhen.common.entity.hell;

import net.minecraft.entity.EntityClassification;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.goal.*;
import net.minecraft.entity.monster.MonsterEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.world.World;

public class SoulWanderingEntity extends MonsterEntity {
    public static final EntityType<SoulWanderingEntity> TYPE = EntityType.Builder
            .<SoulWanderingEntity>create(SoulWanderingEntity::new, EntityClassification.MONSTER)
            .size(1F, 0.8F).build("soul_wandering");
    private float heightOffset = 0.5F;
    private int heightOffsetUpdateTime;

    public SoulWanderingEntity(EntityType<? extends MonsterEntity> type, World worldIn) {
        super(type, worldIn);
        this.applyEntityAI();
    }

    protected void applyEntityAI() {
        this.goalSelector.addGoal(2, new MeleeAttackGoal(this, 1.0D, false));
        this.goalSelector.addGoal(5, new MoveTowardsRestrictionGoal(this, 1.0D));
        this.goalSelector.addGoal(7, new WaterAvoidingRandomWalkingGoal(this, 1.0D, 0.0F));
        this.goalSelector.addGoal(1, new LookAtGoal(this, PlayerEntity.class, 8.0F));
        this.goalSelector.addGoal(8, new LookRandomlyGoal(this));
        this.targetSelector.addGoal(1, (new HurtByTargetGoal(this)).setCallsForHelp());
        this.targetSelector.addGoal(2, new NearestAttackableTargetGoal<>(this, PlayerEntity.class, true));
    }

    @Override
    public boolean onLivingFall(float distance, float damageMultiplier) {
        return false;
    }

    @Override
    public void livingTick() {
        if (!this.onGround && this.getMotion().y < 0.0D) {
            this.setMotion(this.getMotion().mul(1.0D, 0.8D, 1.0D));
        }

        super.livingTick();
    }

    @Override
    protected void updateAITasks() {
        super.updateAITasks();
    }
}
